﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
namespace FPTPages.StatisticPage
{
    public partial class TTDB : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataSet ds = new DataSet();
                string sql = "select teamId, teamName from teams";
                string url = ConfigurationManager.ConnectionStrings["ProjectDatabaseConnectionString2"].ToString();
                using (SqlConnection con = new SqlConnection(url))
                {
                    using (SqlDataAdapter da = new SqlDataAdapter(sql,con))
                    {
                        da.Fill(ds,"Teams");
                    }
                }

                //Add items to dropdownlist

                ddlTeams.DataSource = ds.Tables["teams"];
                ddlTeams.DataTextField = "teamName";
                ddlTeams.DataValueField = "teamId";
                ddlTeams.DataBind();
            }
        }

        protected void ddlTeams_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            string sql = "select * from TeamInfo where teamID = " + ddlTeams.SelectedValue.ToString();
            string url = ConfigurationManager.ConnectionStrings["ProjectDatabaseConnectionString2"].ToString();
            using (SqlConnection con = new SqlConnection(url))
            {
                using (SqlDataAdapter da = new SqlDataAdapter(sql, con))
                {
                    da.Fill(ds, "TeamInfo");
                }
            }

            gdvTTDB.DataSource = ds.Tables["TeamInfo"];
            gdvTTDB.DataBind();
        }
    }
}